package com.agriculture.repository;

import com.agriculture.entity.DevicePositionHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface DevicePositionHistoryRepository extends JpaRepository<DevicePositionHistory, Integer> {
    
    @Query("SELECT h FROM DevicePositionHistory h WHERE h.deviceId = :deviceId AND h.recordedTime >= :startTime AND h.recordedTime <= :endTime ORDER BY h.recordedTime ASC")
    List<DevicePositionHistory> findByDeviceIdAndTimeRange(
            @Param("deviceId") Integer deviceId, 
            @Param("startTime") LocalDateTime startTime, 
            @Param("endTime") LocalDateTime endTime
    );
    
    List<DevicePositionHistory> findByDeviceIdOrderByRecordedTimeAsc(Integer deviceId);
}